<template>
  <div>
    <!-- 面包屑导航区 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>车间库存管理</el-breadcrumb-item>
      <el-breadcrumb-item>车间库存接收</el-breadcrumb-item>
    </el-breadcrumb>
    <!-- 卡片视图 -->
    <el-card>
      <el-row :gutter="10">
        <el-col :span="7">
          <el-input placeholder="请输入物料编号检索" v-model="query">
            <template #append>
              <el-button icon="el-icon-search" @click="getList">检索</el-button>
            </template>
          </el-input>
        </el-col>
        <el-col span="4">
          <el-button
            type="primary"
            icon="el-icon-plus"
            @click="addDialogVisible = true"
            >新增</el-button
          >
        </el-col>
      </el-row>
      <!-- 表格区域 -->
      <el-table
        stripe
        border
        ref="multipleTable"
        :data="workshopInventoryList"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
      >
        <el-table-column prop="id" label="id" width="220" align="center">
        </el-table-column>
        <el-table-column
          prop="item"
          label="物料编号"
          width="220"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="item_sfc" label="SFC" width="240" align="center">
        </el-table-column>
        <el-table-column
          prop="receive"
          label="接收数量"
          width="220"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="site"
          label="挂靠站点"
          width="240"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="by_user"
          label="创建人"
          width="240"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="create_time"
          label="创建时间"
          width="220"
          align="center"
        >
          <template #default="scope">
            {{ formatDate(scope.row.create_time) }}
          </template>
        </el-table-column>
      </el-table>
      <!-- 分页区域 -->
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="pageNow"
        :page-sizes="[1, 2, 5, 10]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="rowCount"
      >
      </el-pagination>
    </el-card>
    <!-- 添加对话框 -->
    <el-dialog title="开始接收批次" v-model="addDialogVisible" width="40%">
        <!-- 二级对话框 -->
    <el-dialog title="物料列表" v-model="codeDV" width="40%" append-to-body>
      <!-- 对话框内容 -->
      <el-table
        stripe
        border
        ref="multipleTable"
        :data="codeList"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        size="small"
      >
        <el-table-column prop="id" label="id" width="auto" align="center">
        </el-table-column>
        <el-table-column
          prop="item_no"
          label="物料编号"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="item_name"
          label="物料名称"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="item_desc"
          label="物料描述"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column label="操作" width="120" align="center">
          <template #default="scope">
            <el-button
              size="mini"
              @click="addCode(scope.row)"
            >选择</el-button>
          </template>
        </el-table-column>
      </el-table>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="codeDV = false">取 消</el-button>
        </span>
      </template>
    </el-dialog>
    <!-- 二级对话框结束 -->
      <!-- 对话框内容 -->
      <el-form
        :model="addForm"
        status-icon
        :rules="addFormrules"
        ref="addFormRef"
        label-width="135px"
      >
        <el-form-item label="所属站点" prop="site">
          <el-input v-model="addForm.site" disabled></el-input>
        </el-form-item>
        <el-form-item label="接收物料" prop="nc_code">
          <el-input v-model="addForm.nc_code" placeholder="请输入接收物料">
            <template #suffix>
              <i class="el-input__icon el-icon-search" @click="addcode"></i>
            </template>
          </el-input>
        </el-form-item>
        <el-form-item label="物料批次" prop="nc_code_desc">
          <el-input
            v-model="addForm.nc_code_desc"
            placeholder="请输入物料批次"
          ></el-input>
        </el-form-item>
        <el-form-item label="接收SFC" prop="nc_code_group_no">
          <el-input
            v-model="addForm.nc_code_group_no"
            placeholder="请输入接收SFC编号"
          ></el-input>
        </el-form-item>
      </el-form>
      <div v-show="receiveTable">
        <el-table
        stripe
        border
        :data="receiveList"
        tooltip-effect="dark"
        style="width: 100%"
        @selection-change="handleSelectionChange"
        size="small"
      >
        <el-table-column prop="sfc" label="sfc" width="auto" align="center">
        </el-table-column>
        <el-table-column
          prop="item_no"
          label="物料编号"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="item_name"
          label="物料名称"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="item_desc"
          label="物料描述"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="site"
          label="挂靠站点"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="by_user"
          label="创建人"
          width="160"
          align="center"
        >
        </el-table-column>
        <el-table-column label="操作" width="120" align="center">
          <template #default="scope">
            <el-button
              size="mini"
              @click="choicesfc(scope.row)"
            >接收</el-button>
          </template>
        </el-table-column>
        </el-table>
      </div>
      <template #footer>
        <span class="dialog-footer">
          <el-button type="primary" @click="add">开始接收</el-button>
          <el-button @click="addDialogVisible = false">取消接收</el-button>
        </span>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import axios from "axios";
export default {
  data() {
    return {
      workshopInventoryList: [],
      pageCount: 1,
      pageNow: 1,
      pageSize: 10,
      rowCount: 0,
      query: "",
      // 显示添加对话框
      addDialogVisible: false,
      codeDV:false,
      codeList:[],
      receiveTable:false,
      receiveList:[],
      addForm: {
        site: "*",
        nc_code: "",
        nc_code_desc: "",
        nc_code_group_no: "",
        state: "",
      },
      addFormrules: {
        site: [],
        nc_code: [
          {
            required: true,
            message: "请输入接收物料",
            trigger: "blur",
          },
        ],
        nc_code_desc: [
          {
            required: true,
            message: "请输入物料批次",
            trigger: "blur",
          },
        ],
        nc_code_group_no: [
          {
            required: true,
            message: "请输入不良代码组",
            trigger: "blur",
          },
        ],
        state: [
          {
            required: true,
            message: "请输入接收SFC编号",
            trigger: "blur",
          },
        ],
      },
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    getList() {
      this.$axios({
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
        method: "post",
        url: "/IE_MES/workshop_inventory/workshop_inventory_findByPage.shtml",
        data: this.$qs.stringify({
          pageSize: this.pageSize,
          pageNow: this.pageNow,
          "workshopInventoryFormMap.item": this.query,
        }),
      }).then((res) => {
        this.workshopInventoryList = res.data.records;
        this.pageCount = res.data.pageCount;
        this.pageNow = res.data.pageNow;
        this.pageSize = res.data.pageSize;
        this.rowCount = res.data.rowCount;
      });
    },
    addcode() {
      this.codeDV = true;
      this.$axios({
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
        method: "post",
        url: "/IE_MES/item_resource/getItemChildFindByPage.shtml",
        data: this.$qs.stringify({}),
      }).then((res) => {
        this.codeList = res.data.records;
      });
    },
    addCode(row) {
      this.addForm.nc_code = row.item_no;
      this.codeDV = false;
    },
    add(){
      this.receiveTable = true;
      this.$axios({
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
        method: "post",
        url: "/IE_MES/workshop_inventory/workshop_inventory_getItemInfo.shtml?sfc="+this.addForm.nc_code_group_no+"&item="+this.addForm.nc_code+"&site=*",
        data: this.$qs.stringify({
        }),
      }).then((res) => {
        this.receiveList = res.data.records;
        console.log(this.receiveList);
      });
    },
    choicesfc(row){
      this.$axios({
        headers: {
          "Content-Type": "application/x-www-form-urlencoded; charset=UTF-8",
        },
        method: "post",
        url: "/IE_MES/workshop_inventory/workshop_inventory_addEntity.shtml",
        data: this.$qs.stringify({
          "workshopInventoryFormMap.site":row.site,
          "workshopInventoryFormMap.item":row.item_no,
          "workshopInventoryFormMap.batch":this.addForm.nc_code_desc,
          "workshopInventoryFormMap.itemSfc":row.sfc,
          "workshopInventoryFormMap.item_sfcs":row.sfc,
          "workshopInventoryFormMap.item_nos":row.item_no
        }),
      }).then((res) => {
        if (res.data == "{\"result\":\"success\",\"score\":\"\"}") {
              this.$message({
                type: "success",
                message: "接收成功!",
              });
              this.addDialogVisible = false
              this.getList()
            }
      });
    },
    handleSizeChange(newSize) {
      this.pageSize = newSize;
      this.getList();
    },
    handleCurrentChange(newPage) {
      this.pageNow = newPage;
      this.getList();
    },
    formatDate(data) {
      var date = new Date(data);
      var YY = date.getFullYear() + "-";
      var MM =
        (date.getMonth() + 1 < 10
          ? "0" + (date.getMonth() + 1)
          : date.getMonth() + 1) + "-";
      var DD = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
      var hh =
        (date.getHours() < 10 ? "0" + date.getHours() : date.getHours()) + ":";
      var mm =
        (date.getMinutes() < 10 ? "0" + date.getMinutes() : date.getMinutes()) +
        ":";
      var ss =
        date.getSeconds() < 10 ? "0" + date.getSeconds() : date.getSeconds();
      return YY + MM + DD + " " + hh + mm + ss;
    },
  },
};
</script>

<style lang="less" scoped>
</style>
